<?php
/**
 * <pre>
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT      : rubik-base
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * AbstractHtmlFilter lớp Abstract dùng để lớp con HTMLFilter extends.
 * Cấu trúc của lớp con: NewsHtmlFilter extends AbstractHtmlFilter
 * 	các public properties sẽ được dùng để tạo ra filter box
 * 
 * Cú pháp của lớp properties lớp con:
 * 		var $<giá trị> = "<Tên cần hiển thị trong combobox>";
 *
 * </pre>
 * 
 * @version 		1.0
 * @author			Dang Nhon Hoa <hoadn@rubik.com.vn>
 * @access			public
 * @package			rubik.base.html
 *
 * Created on	: May 24, 2009
 */

class AbstractHtmlCheckBox {
	
	/**
	 * Name of current combobox
	 *
	 * @var string
	 */
	var $_chkName = null;
	
	/**
	 * Value of current combobox
	 *
	 * @var array
	 */
	var $_selectedValues = null;
	
	/**
	 * The array for containing data
	 *
	 * @var array
	 */ 
	var $_arrayData;
	
	/**
	 * Constructor
	 *
	 * @param string $cbxName the name of COMBOBOX control will ben generate
	 * @param string/array $valueOrArrayContain this array normaly is $_POST or $_GET or $_REQUEST
	 */
	function __construct($cbxName, $valueOrArrayContain = null) {
		$this->_chkName = $cbxName;
		$this->setValue ( $valueOrArrayContain );
	}
	
	/**
	 * Set the value for this control from the array contain the value
	 *
	 * @param string/array $valueOrArrayContain this array normaly is $_POST or $_GET or $_REQUEST
	 */
	function setValue($valueOrArrayContain) {
		$this->_selectedValues = RubikHelper::getValueFrom($valueOrArrayContain, $this->_chkName);
		if (!$this->_selectedValues && is_array($valueOrArrayContain)) {
			$this->_selectedValues = $valueOrArrayContain;
			return true;
		}
		return false;
	}
	
	/**
	 * Get the value of combobox
	 *
	 * @return array
	 */
	function getSelectedValue() {
		return $this->_selectedValues;
	}
	
	/**
	 * Create HTML text for the combobox
	 *
	 * @param $extAttributes
	 * @param $htmlIdPrefix
	 * @param $wrapper string wrapper is the name tag of wrapper maye: 'div', 'span'
	 * @param $wraperAttributes the attribute for the wrapper
	 * @return string
	 */
	function createCheckBox($extAttributes = "", $htmlIdPrefix = "", $wrapper=null, $wraperAttributes = null) {
		$inputName = $this->_chkName;
		
		if (empty($this->_arrayData)) {
			$vars = get_object_vars ( $this );
			foreach ( $vars as $key => $value ) {
				if ('_' == substr ( $key, 0, 1 )) {
					continue;
				}
				$fields [$key] = $value;
			}
			$this->_arrayData = &$fields;
		}
		RCoreImporter::cls("helper.RHtmlHelper" );
		return RHtmlHelper::createCheckBoxListHtml ($inputName , $this->_arrayData, $this->_selectedValues, 
											$extAttributes, $htmlIdPrefix, $wrapper, $wraperAttributes);
	}
	
	/**
	 * CheckBox
	 *
	 * @return string
	 */
	function getCbxName() {
		return $this->_chkName;
	}
}
?>